var tableIns;//表格实例
layui.use(['laydate','form','table'], function(){
    dict2Select("dimension","s_dimension");
    var form = layui.form;
    form.render();
    var laydate = layui.laydate;
    //执行一个laydate实例
    laydate.render({
        elem: '#s_sDate' //指定元素
    });
    laydate.render({
        elem: '#s_eDate'
    });
    var url="/mm/rules";

    var table = layui.table;
    tableIns = table.render({
        elem: '#listTable'
        , url: appendCtx(url)
        , page: true
        , even: true
        , cols: [[ //表头
            {field: 'id', title: 'ID',  align: 'center', width: 100, fixed: true},
            {field: 'ruleNo', title: '规则编号',  align: 'center', width: 150, fixed: true},
            {field: 'ruleName', title: '规则名称', align: 'center',width: 200, fixed: true},
            {field: 'version', title: '版本号', align: 'center',width: 100, fixed: true},
            {field: 'dimension', title: '所属维度', align: 'center', width: 200, fixed: true,templet:function(d){
                    if(d.dimension){
                        return translate("dimension",d.dimension);
                    }
                    return "";
                }},
            {field: 'exeOrder', title: '决策序号',  align: 'center'},
            {field: 'maxScore', title: '最高分值',align: 'center'},
            {field: 'createDate', title: '创建时间',align: 'center',width: 180},
            {field: 'creatorName', title: '创建人',align: 'center'},
            {field: 'modifyDate', title: '修改时间',align: 'center',width: 180},
            {field: 'modifyName', title: '修改人',align: 'center'},
            {field: '', title: '操作', align: 'center',width: 260,toolbar: '#openBar',}
        ]]
        , request: {
            pageName: 'pageNo' //页码的参数名称，默认：page
            , limitName: 'pageSize' //每页数据量的参数名，默认：limit
        }
        , parseData: function (res) { //res 即为原始返回的数据
            return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.data.total, //解析数据长度
                "data": res.data.list //解析数据列表
                ,"attr":res.attr
            };
        }
    });
    form.on('submit(search)', function(formData){
        tableIns.reload({
            where:formData.field,
            page:{
                curr: 1
            }
        });
        return false;
    });
    form.on('submit(export)', function(formData){
        window.location.href =appendCtx("/mm/rules/excel?"+json2Url(formData.field));
        return false;
    });
    form.on('submit(addNew)', function(formData){
        update(null,0);
        return false;
    });

});
function refreshTableData() {
    tableIns.reload({});
}

function update(id,type) {
    layer.open({
        type: 2,
        title: '修改规则',
        area: ['1500px', '780px'],
        content: 'modifyRule.html?id=' + id+'&type='+type,
    });
}

function copy(id) {
    io.post('/mm/rules/'+id,null,function (result) {
        //刷新列表
        refreshTableData();
        });
}

function deletedate(id) {
    io.delete('/mm/rules/' + id, function (result) {
        //刷新列表
        refreshTableData();
    });
}